#!/usr/bin/env python
""" Forms a 'text entry window' that takes a text up to 8 chars """
""" wide and prints it. """
import pygtk
pygtk.require('2.0')
import gtk,sys

class GUI:
	def delete_event(self, widget, event, data=None):
		# If you return FALSE in the "delete_event" signal handler,
		# GTK will emit the "destroy" signal. Returning TRUE means
		# you don't want the window to be destroyed.
		# This is useful for popping up 'are you sure you want to quit?'
		# type dialogs.
		print "delete event occurred"

		# Change FALSE to TRUE and the main window will not be destroyed
		# with a "delete_event".
		return False
	""" Form the GUI and bootstrap the application """
	def __init__(self):
		self.root = gtk.Window(type=gtk.WINDOW_TOPLEVEL)

		
		title=sys.argv[1]
		self.root.set_title(title)
		self.root.set_position(gtk.WIN_POS_CENTER)
		self.root.set_skip_taskbar_hint(True)

		# When the window is given the "delete_event" signal (this is given
		# by the window manager, usually by the "close" option, or on the
		# titlebar), we ask it to call the delete_event () function
		# as defined above. The data passed to the callback
		# function is NULL and is ignored in the callback function.
		self.root.connect("delete_event", self.delete_event)

		# Here we connect the "destroy" event to a signal handler.  
		# This event occurs when we call gtk_widget_destroy() on the window,
		# or if we return FALSE in the "delete_event" callback.
		self.root.connect("destroy", gtk.main_quit)

		# Button box
		self.mbox = gtk.VBox()
		self.root.add(self.mbox)

		# Message for the window 
		self.winput= gtk.Entry(8)
		#self.winput.set_visibility(False) # password type
		self.mbox.add(self.winput)
		self.winput.connect("activate", self.input_cb)

		## OK button
		#self.okbut = gtk.Button("OK")
		#self.mbox.add(self.okbut)
		#self.okbut.connect("pressed", self.input_cb)

		# Show all the windows
		self.root.show_all()
		self.mainloop()

	""" This is the Apps mainloop """
	def mainloop(self):
		gtk.main()

	def input_cb(self, pwidget):
		print (self.winput.get_text())
		gtk.main_quit()

if __name__ == '__main__':
	if len(sys.argv)>1:
		myGUI = GUI()
	else:
		print('python mstiler_ask.py title')
